/*
 * Created on Mar 3, 2008
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.scalar.chiptrack.finance.openpo.actioncommands;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.ChipTrackExtendedAction;
import com.scalar.chiptrack.finance.openpo.dao.PurchaseOrderDAO;
import com.scalar.chiptrack.finance.openpo.forms.PurchaseOrderForm;
import com.scalar.chiptrack.users.ErrorReport;
import com.scalar.chiptrack.utils.Logger;

/**
 * @author ravi
 */
public class PurchaseOrderLoadVendorPartNumberCommand extends ChipTrackExtendedAction 
{

	public ActionForward executeRequest(ActionMapping mapping, ActionForm form,	HttpServletRequest request, HttpServletResponse response)throws Exception 
	{
        HashMap errors              = ( HashMap ) request.getAttribute( ERROR_MESSAGES );
        HashMap info                = ( HashMap ) request.getAttribute( INFO_MESSAGES );
        PurchaseOrderForm purchaseOrderForm = ( PurchaseOrderForm ) form;
		String actionForward 		= "Search";
        HttpSession mSession 		= request.getSession();

		try
        {
			request.getParameter( "index" );
            request.setAttribute( "vendorPartNumberList", PurchaseOrderDAO.loadVendorPartNumbers( request.getParameter( "processStepId" ), request.getParameter( "vendorId" ) ) );
            request.setAttribute( "Index", request.getParameter( "index" ) );
            actionForward = "purchaseOrderLoadVendorPartNumber";
       	}
        catch ( Exception e )
        {
            Logger.error( ERRROR_LOADING_PACKAGE_TYPE_IN_PURCHASE_ORDER_LINE_ITEM, e );
            errors.put( ERROR_INTERNAL_SERVER_ERROR, ERRROR_LOADING_PACKAGE_TYPE_IN_PURCHASE_ORDER_LINE_ITEM );
			mSession.setAttribute( ERROR_REPORT_OBJECT, new ErrorReport( ERRROR_LOADING_PACKAGE_TYPE_IN_PURCHASE_ORDER_LINE_ITEM, e ) );
            actionForward = "load";
        }

		request.setAttribute( ERROR_MESSAGES, errors );
		request.setAttribute( INFO_MESSAGES, info );
		return mapping.findForward( actionForward );
    }
}